```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>算法解析：搜索旋转排序数组</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-container {
            background: #2d3748;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background: #1a202c;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 16px;
            color: #e2e8f0;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            gap: 6px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .code-dot-red {
            background: #f56565;
        }
        .code-dot-yellow {
            background: #f6e05e;
        }
        .code-dot-green {
            background: #48bb78;
        }
        .code-title {
            margin-left: 12px;
            font-size: 14px;
            font-weight: 500;
        }
        .code-body {
            padding: 16px;
            color: #e2e8f0;
            font-family: 'Courier New', Courier, monospace;
            overflow-x: auto;
        }
        .keyword {
            color: #f6ad55;
        }
        .comment {
            color: #a0aec0;
            font-style: italic;
        }
        .string {
            color: #68d391;
        }
        .number {
            color: #63b3ed;
        }
        .highlight-card {
            transition: all 0.3s ease;
        }
        .highlight-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .section-divider {
            position: relative;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent);
        }
        .mermaid-container {
            background: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">搜索旋转排序数组</h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8 leading-relaxed">利用二分查找算法在旋转后的有序数组中高效搜索目标值</p>
                <div class="flex justify-center space-x-4">
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">#二分查找</span>
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">#算法优化</span>
                    <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm font-medium">#O(log n)</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-16 max-w-6xl">
        <!-- Problem Statement -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                    <i class="fas fa-question text-purple-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
            </div>
            <div class="bg-white rounded-xl shadow-md p-8 mb-8">
                <p class="text-lg text-gray-700 leading-relaxed">给定一个升序排列的整数数组 <code class="bg-gray-100 px-2 py-1 rounded">nums</code>，经过某个未知的旋转后，得到一个新的数组。给定一个目标值 <code class="bg-gray-100 px-2 py-1 rounded">target</code>，若存在目标值则返回其索引，否则返回 <code class="bg-gray-100 px-2 py-1 rounded">-1</code>。</p>
                <p class="text-lg text-gray-700 leading-relaxed mt-4">要求时间复杂度为 <code class="bg-gray-100 px-2 py-1 rounded">O(log n)</code>。</p>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden highlight-card">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-8 h-8 rounded-full bg-blue-100 flex items-center justify-center mr-3">
                                <i class="fas fa-lightbulb text-blue-600"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">核心考点</h3>
                        </div>
                        <div class="pl-11">
                            <p class="text-lg text-gray-700">二分查找算法及其变种应用</p>
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden highlight-card">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-8 h-8 rounded-full bg-green-100 flex items-center justify-center mr-3">
                                <i class="fas fa-bullseye text-green-600"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">复杂度要求</h3>
                        </div>
                        <div class="pl-11">
                            <p class="text-lg text-gray-700">时间复杂度: O(log n)</p>
                            <p class="text-lg text-gray-700">空间复杂度: O(1)</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider my-12"></div>

        <!-- Solution Approach -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                    <i class="fas fa-project-diagram text-blue-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">解题思路</h2>
            </div>
            
            <div class="grid md:grid-cols-3 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md p-6 highlight-card">
                    <div class="text-blue-600 text-2xl mb-4">
                        <i class="fas fa-search"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">二分查找基础</h3>
                    <p class="text-gray-600">标准的二分查找适用于有序数组，通过不断将搜索范围减半来实现O(log n)时间复杂度。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 highlight-card">
                    <div class="text-purple-600 text-2xl mb-4">
                        <i class="fas fa-random"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">旋转数组特性</h3>
                    <p class="text-gray-600">旋转后的数组可以看作两个有序子数组的组合，其中一个子数组的所有元素都大于另一个子数组。</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 highlight-card">
                    <div class="text-green-600 text-2xl mb-4">
                        <i class="fas fa-code-branch"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">条件判断</h3>
                    <p class="text-gray-600">需要判断中间点位于哪个有序部分，然后根据目标值与边界值的关系决定搜索方向。</p>
                </div>
            </div>

            <div class="mermaid-container mb-8">
                <div class="mermaid">
                    graph TD
                    A[开始] --> B[边界检查]
                    B --> C{数组为空?}
                    C -->|是| D[返回-1]
                    C -->|否| E[初始化左右指针]
                    E --> F{左指针 ≤ 右指针?}
                    F -->|否| G[返回-1]
                    F -->|是| H[计算中间索引]
                    H --> I{中间值等于目标值?}
                    I -->|是| J[返回中间索引]
                    I -->|否| K{左半部分有序?}
                    K -->|是| L[目标值在左半部分范围内?]
                    L -->|是| M[右指针移动到中间-1]
                    L -->|否| N[左指针移动到中间+1]
                    K -->|否| O[目标值在右半部分范围内?]
                    O -->|是| P[左指针移动到中间+1]
                    O -->|否| Q[右指针移动到中间-1]
                    M --> F
                    N --> F
                    P --> F
                    Q --> F
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md p-8">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800">详细步骤解析</h3>
                <ol class="space-y-6">
                    <li class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <div class="flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full text-blue-600 font-bold">1</div>
                        </div>
                        <div>
                            <h4 class="text-xl font-medium text-gray-800 mb-2">初始化指针</h4>
                            <p class="text-gray-600">设置左指针 <code class="bg-gray-100 px-1.5 py-0.5 rounded">left = 0</code> 和右指针 <code class="bg-gray-100 px-1.5 py-0.5 rounded">right = nums.length - 1</code> 来标记当前搜索范围的边界。</p>
                        </div>
                    </li>
                    <li class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <div class="flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full text-blue-600 font-bold">2</div>
                        </div>
                        <div>
                            <h4 class="text-xl font-medium text-gray-800 mb-2">计算中间点</h4>
                            <p class="text-gray-600">使用 <code class="bg-gray-100 px-1.5 py-0.5 rounded">mid = left + (right - left) / 2</code> 计算中间索引，避免整数溢出。</p>
                        </div>
                    </li>
                    <li class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <div class="flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full text-blue-600 font-bold">3</div>
                        </div>
                        <div>
                            <h4 class="text-xl font-medium text-gray-800 mb-2">判断中间点位置</h4>
                            <p class="text-gray-600">比较 <code class="bg-gray-100 px-1.5 py-0.5 rounded">nums[left]</code> 和 <code class="bg-gray-100 px-1.5 py-0.5 rounded">nums[mid]</code> 确定中间点位于哪个有序部分。</p>
                        </div>
                    </li>
                    <li class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <div class="flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full text-blue-600 font-bold">4</div>
                        </div>
                        <div>
                            <h4 class="text-xl font-medium text-gray-800 mb-2">调整搜索范围</h4>
                            <p class="text-gray-600">根据目标值与边界值的关系，调整 <code class="bg-gray-100 px-1.5 py-0.5 rounded">left</code> 或 <code class="bg-gray-100 px-1.5 py-0.5 rounded">right</code> 指针缩小搜索范围。</p>
                        </div>
                    </li>
                    <li class="flex">
                        <div class="flex-shrink-0 mr-4">
                            <div class="flex items-center justify-center w-8 h-8 bg-blue-100 rounded-full text-blue-600 font-bold">5</div>
                        </div>
                        <div>
                            <h4 class="text-xl font-medium text-gray-800 mb-2">终止条件</h4>
                            <p class="text-gray-600">当 <code class="bg-gray-100 px-1.5 py-0.5 rounded">left > right</code> 时终止循环，表示未找到目标值。</p>
                        </div>
                    </li>
                </ol>
            </div>
        </section>

        <div class="section-divider my-12"></div>

        <!-- Code Example -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center mr-4">
                    <i class="fas fa-code text-green-600 text-xl"></i>
                </div>
                <h2 class="text-3xl font-bold text-gray-800">示例代码</h2>
            </div>
            
            <div class="code-container mb-8">
                <div class="code-header">
                    <div class="code-dots">
                        <div class="code-dot code-dot-red"></div>
                        <div class="code-dot code-dot-yellow"></div>
                        <div class="code-dot code-dot-green"></div>
                    </div>
                    <div class="code-title">SearchInRotatedSortedArray.java</div>
                </div>
                <div class="code-body">
                    <pre><code><span class="keyword">public</span> <span class="keyword">int</span> search(<span class="keyword">int</span>[] nums, <span class="keyword">int</span> target) {
    <span class="comment">// 边界检查</span>
    <span class="keyword">if</span> (nums == <span class="keyword">null</span> || nums.length == <span class="number">0</span>) {
        <span class="keyword">return</span> -<span class="number">1</span>;
    }
    
    <span class="comment">// 初始化左右指针</span>
    <span class="keyword">int</span> left = <span class="number">0</span>;
    <span class="keyword">int</span> right = nums.length - <span class="number">1</span>;
    
    <span class="comment">// 二分查找</span>
    <span class="keyword">while</span> (left <= right) {
        <span class="comment">// 计算中间位置，避免整数溢出</span>
        <span class="keyword">int</span> mid = left + (right - left) / <span class="number">2</span>;
        
        <span class="comment">// 如果找到目标值，直接返回索引</span>
        <span class="keyword">if</span> (nums[mid] == target) {
            <span class="keyword">return</span> mid;
        }
        
        <span class="comment">// 判断中间点在哪个部分（左半部分有序还是右半部分有序）</span>
        <span class="keyword">if</span> (nums[left] <= nums[mid]) {
            <span class="comment">// 左半部分有序</span>
            <span class="comment">// 检查目标值是否在左半部分的有序区间内</span>
            <span class="keyword">if</span> (nums[left] <= target && target < nums[mid]) {
                <span class="comment">// 目标在左半部分，缩小搜索范围到左半部分</span>
                right = mid - <span class="number">1</span>;
            } <span class="keyword">else</span> {
                <span class="comment">// 目标在右半部分，缩小搜索范围到右半部分</span>
                left = mid + <span class="number">1</span>;
            }
        } <span class="keyword">else</span> {
            <span class="comment">// 右半部分有序</span>
            <span class="comment">// 检查目标值是否在右半部分的有序区间内</span>
            <span class="keyword">if</span> (nums[mid] < target && target <= nums[right]) {
                <span class="comment">// 目标在右半部分，缩小搜索范围到右半部分</span>
                left = mid + <span class="number">1</span>;
            } <span class="keyword">else</span> {
                <span class="comment">// 目标在左半部分，缩小搜索范围到左半部分</span>
                right = mid - <span class="number">1</span>;
            }
        }
    }
    
    <span class="comment">// 未找到目标值</span>
    <span class="keyword">return</span> -<span class="number">1</span>;
}</code></pre>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">代码分析</h3>
                    <ul class="space-y-3 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>边界检查防止空指针异常</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>使用 <code class="bg-gray-100 px-1 py-0.5 rounded">left + (right - left) / 2</code> 计算中间值防止整数溢出</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>每次迭代将搜索范围减半，保证O(log n)时间复杂度</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>通过比较中间值与边界值确定哪部分是有序的</span>
                        </li>
                    </ul>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800">复杂度分析</h3>
                    <div class="space-y-4">
                        <div>
                            <div class="flex justify-between mb-1">
                                <span class="text-gray-700 font-medium">时间复杂度</span>
                                <span class="text-blue-600 font-bold">O(log n)</span>
                            </div>
                            <div class="w-full bg-gray-200 rounded-full h-2.5">
                                <div class="bg-blue-600 h-2.5 rounded-full" style="width: 30%"></div>
                            </div>
                            <p class="text-sm text-gray-500 mt-1">每次迭代都将搜索范围减半</p>
                        </div>
                        <div>
                            <div class="flex justify-between mb-1">
                                <span class="text-gray-700 font-medium">空间复杂度</span>
                                <span class="text-green-600 font-bold">O(1)</span>
                            </div>
                            <div class="w-full bg-gray-200 rounded-full h-2.5">
                                <div class="bg-green-600 h-2.5 rounded-full" style="width: 10%"></div>
                            </div>
                            <p class="text-sm text-gray-500 mt-1">只使用了常数级别的额外空间</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```